﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2-11.aspx.cs" Inherits="Example.WebForm2_11" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>自定义验证示例</title>
  <script type="text/javascript">
    function phoneCheck(source, args) {
      var phone = args.Value;
      args.IsValid = false;
      if (phone.length == 11)
        if (phone.charAt(0) == '1') {
          for (var i = 1; i < phone.length; i++)
            if (phone.charAt(i) < '0' && phone(i) > '9')
              break;
          if (i == phone.length)
            args.IsValid = true;
        }
    }
  </script>
</head>
<body>
  <form id="form1" runat="server">
    自定义验证示例<hr />
    <div>
      手机号：<asp:TextBox ID="txtPhone" runat="server"></asp:TextBox>
      <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="手机号格式不正确" ControlToValidate="txtPhone" ClientValidationFunction="phoneCheck"></asp:CustomValidator>
    </div>
  </form>
</body>
</html>
